#! /bin/sh

GXINE_ROOT="`expr match "$GXINE_ROOT" '[^/]' >/dev/null || pwd`/`dirname "$0"`"

if test "$1" = -h || test "$1" = --help; then
  cat <<EOF
Usage:
  $0 ...
  $0 --gdb ...
In the latter form, options and MRLs are passed to gdb via 'set args'.

EOF
  exec "$GXINE_ROOT/src/gxine" --help
fi

unset USEGDB
if test "$1" = --gdb; then
  USEGDB=y
  shift
fi

export GXINE_PLUGINDIR="$GXINE_ROOT/browser_plugin"
export GXINE_BINDIR="$GXINE_ROOT/src"
export GXINE_LOGODIR="$GXINE_ROOT/pixmaps"
export GXINE_PIXMAPDIR="$GXINE_ROOT/pixmaps"
export GXINE_ICONDIR="$GXINE_ROOT/pixmaps"
export GXINE_MISCDIR="$GXINE_ROOT/misc"
export GXINE_CONFDIR="$GXINE_ROOT/misc"

cleanup ()
{
  test "$GDBCMD" != '' && rm -f "$GDBCMD"
}

if test "$USEGDB" = y; then
  # bash: exec gdb "$GXINE_ROOT/src/gxine" <(echo set args "$@")
  unset GDBCMD
  trap cleanup EXIT
  GDBCMD="`tempfile`"
  echo set args "$@" >>"$GDBCMD"
  gdb "$GXINE_ROOT/src/gxine" -x "$GDBCMD"
else
  exec "$GXINE_ROOT/src/gxine" "$@"
fi
